home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / comm / mail / PSMail.lha / PSMail / Prolog1.2.ps < prev    next >
Encoding:
Text File  |  2000-01-17  |  8.9 KB  |  401 lines

  1. %%
  2. %% YAMPSMail V1.2 © 1999 by Alastair M. Robinson
  3. %% Just a bit of PostScript code to print E-Mails from YAM
  4. %% in a slightly more presentable format.
  5. %%
  6. %% The routines presented here are a subset of some automatic text
  7. %% formatting routines I wrote a while back.  Feel free to modify them
  8. %% to suit your own needs/tastes, but don't try to pass them off as
  9. %% your own work.
  10. %%
  11. %% If you've made some cool changes I'd appreciate seeing the result!
  12. %% Mail me at:blackfive@fakenhamweb.co.uk
  13. %%
  14.  
  15. %% BeginProlog
  16.  
  17. %% If you want to translate PSMail into another language,
  18. %% you can change (Page ) below to (Seite ) or whatever is
  19. %% the equivalent in your language.
  20.  
  21. /PageString (Page ) def
  22. /RasterizingPageString (Rasterizing Page ) def
  23. /PrintingPageString (Printing Page ) def
  24.  
  25. %% The following array contains a list of headers to be printed.
  26. %% Each entry must be of the form:
  27. %% [ /Name (Search key ) (Printed Name)]
  28. %% Name must be unique - if things start behaving strangely, try choosing
  29. %% different names for your custom headers.
  30. %%
  31. %% Printed Name can be changed, allowing you to translate the printout
  32. %% into other languages.
  33. %%
  34. %% The search key is case-sensitive; you might find that you need to
  35. %% define separate entries for different capitalizations, i.e.
  36. %% [ /ContentType1 (Content-type: ) (Content-type: )]
  37. %% [ /ContentType2 (Content-Type: ) (Content-Type: )]
  38. %%
  39. %% Sample entries for the most common headers are listed below, but commented
  40. %% out.  To activate them, just remove the %% signs.
  41.  
  42. /CustomHeaders
  43. [
  44.   [ /MailTo   (To: ) (To: )]
  45.   [ /MailFrom (From: ) (From: )]
  46.   [ /Organisation (Organisation: ) (Organisation: )]
  47. %%  [ /XMailer  (X-Mailer: ) (Mailer: )]
  48. %%  [ /MessageID (Message-ID: ) (Message ID: )]
  49. %%  [ /InReplyTo (In-Reply-To: ) (In Reply To: )]
  50. %%  [ /MIMEVersion (MIME-Version: ) (MIME Version: )]
  51. %%  [ /ContentType1 (Content-type: ) (Content Type: )]
  52. %%  [ /ContentType2 (Content-Type: ) (Content Type: )]
  53. ] def
  54.  
  55. %%
  56. %% The following sizes and font names can be changed to suit your tastes.
  57. %%
  58.  
  59. /BodySize 10 def
  60. /BodyFont {/Palatino} def
  61.  
  62. /HeadingSize 10 def
  63. /HeadingFont {/Palatino-Bold} def
  64.  
  65. /TitleSize 15 def
  66. /TitleFont {/Palatino-BoldItalic} def
  67.  
  68. %%
  69. %% Don't change anything below here unless you know what you're doing.
  70. %%
  71.  
  72. clippath pathbbox
  73. /PageHeight exch def
  74. /PageWidth exch def
  75. /PageBottom exch def
  76. /PageLeft exch def
  77. /PageHeight PageHeight PageBottom  sub def
  78. /PageWidth PageWidth PageLeft sub def
  79. newpath
  80. PageLeft PageBottom translate
  81.  
  82. /HeaderMargin 34 def
  83. /TopMargin PageHeight 20 sub HeaderMargin neg add def
  84. /LeftMargin 45 def
  85. /RightMargin PageWidth 45 sub def
  86. /FooterMargin 20 def
  87. /BottomMargin 25 FooterMargin add def
  88.  
  89. /Columns 1 def
  90. /Gutter 0 def
  91.  
  92. /PageNo 1 def
  93. /PageNoString 8 string def
  94. /Title () def
  95.  
  96. /ListingSize 8 def
  97. /ListingFont {/Courier} def
  98.  
  99. /Leading 2 def
  100.  
  101. /FindFontISO %% name
  102. {
  103.   findfont
  104.   dup /Encoding get 65 get /A eq % Check for symbol or dingbat encoding
  105.   {
  106.     dup length dict begin {1 index /FID ne {def} {pop pop} ifelse} forall
  107.     /Encoding ISOLatin1Encoding def currentdict end
  108.     dup /FontName get dup length string cvs dup length dup
  109.     7 add string 2 index 1 index copy pop
  110.     exch 1 index exch (-Latin1) putinterval exch pop
  111.     cvn exch definefont
  112.   } if
  113. } def
  114.  
  115. /RightAlign %% String XPos YPos
  116. { 2 index stringwidth pop neg 2 index add exch moveto pop show } def
  117.  
  118. /LeftAlign %% String XPos YPos
  119. { moveto show } def
  120.  
  121. /Centre %% String XPos YPos
  122. { exch 2 index stringwidth pop 2 div sub exch moveto show } def
  123.  
  124.  
  125. /SetStatus
  126. {
  127.   (t:YAMPrintStatus) (w) file
  128.   exch 1 index exch writestring
  129.   dup PageNo 15 string cvs writestring
  130.   closefile
  131. } def
  132.  
  133.  
  134. /BeginPage
  135. {
  136.   RasterizingPageString SetStatus
  137.   /ColumnWidth RightMargin LeftMargin neg add
  138.                Gutter Columns -1 add mul neg add
  139.                Columns div def
  140.   /BlockLeftEdge LeftMargin def
  141.   /BlockRightEdge BlockLeftEdge ColumnWidth add def
  142.   /XPos LeftMargin def
  143.   /YPos TopMargin def
  144.   DoHeader DoFooter
  145. } def
  146.  
  147.  
  148. /EndPage
  149. {
  150.   PrintingPageString SetStatus
  151.   showpage
  152.   PageLeft PageBottom translate
  153.   /PageNo PageNo 1 add def
  154. } def
  155.  
  156.  
  157. /DoHeader
  158. {
  159.   2 setlinewidth 0 0 0 setrgbcolor
  160.   LeftMargin -10 add TopMargin 5 add RightMargin 10 add 1 index
  161.   moveto lineto stroke
  162.   TitleFont FindFontISO TitleSize scalefont setfont
  163.   Title LeftMargin TopMargin 12 add LeftAlign
  164. } def
  165.  
  166.  
  167. /DoFooter
  168. {
  169.   2 setlinewidth 0 0 0 setrgbcolor
  170.   LeftMargin -10 add BottomMargin TitleSize neg add RightMargin 10 add 1 index
  171.   moveto lineto stroke
  172.   TitleFont FindFontISO TitleSize 3 mul 4 div scalefont setfont
  173.   /Foot where
  174.   {
  175.     pop Foot LeftMargin RightMargin add 2 div BottomMargin 28 neg add Centre
  176.   } if
  177.   PageString PageNo PageNoString cvs
  178.   stringwidth pop neg RightMargin add BottomMargin 28 neg add RightAlign
  179.   PageNo PageNoString cvs RightMargin BottomMargin 28 neg add RightAlign
  180.   /Date where
  181.   {
  182.     pop Date LeftMargin BottomMargin 28 neg add LeftAlign
  183.   } if
  184. } def
  185.  
  186.  
  187. /ClearMailHeader %% HeaderName ClearMailHeader
  188. {
  189.   dup where {exch undef} {pop} ifelse
  190. } def
  191.  
  192.  
  193. /PrintMailHeaders %% PrintMailHeaders
  194. {
  195.   CustomHeaders
  196.   {
  197.     dup 2 get exch
  198.     0 get dup where
  199.     {
  200.       exch get concatstrings HeadingLeft
  201.     }
  202.     { pop pop } ifelse
  203.   } forall
  204. } def
  205.  
  206.  
  207. /DefMailHeader %% HeaderLine HeaderName HeaderText DefMailHeader
  208. {
  209.   exch /HeaderName exch def
  210.   search
  211.   {
  212.     length 0 eq
  213.     {
  214.       pop HeaderName exch def pop () ()
  215.     }
  216.     {
  217.       pop pop dup
  218.     } ifelse
  219.   } if
  220. } def
  221.  
  222.  
  223. /ParseMailHeader %% filename
  224. {
  225.   /Title () def
  226.   /Date () def
  227.   CustomHeaders { 0 get dup where {exch undef} {pop} ifelse } forall
  228.   /File exch (r) file def
  229.   /cfp File fileposition def
  230.   File 4096 string readline
  231.   {
  232.     length 0 eq not { File cfp setfileposition } if
  233.   }
  234.   { exit } ifelse
  235.   {
  236.     File 4096 string readline
  237.     true eq
  238.       {
  239.         dup length 0 eq { pop exit } if
  240.         dup
  241.         CustomHeaders
  242.         { dup 0 get exch 1 get DefMailHeader } forall
  243.         (Subject: ) search
  244.         {
  245.           length 0 eq
  246.           { pop /Title exch def pop () () }
  247.           { pop pop dup } ifelse
  248.         } if
  249.         (Date: ) search
  250.         {
  251.           length 0 eq
  252.           { pop /Date exch def pop () () }
  253.           { pop pop dup } ifelse
  254.         } if
  255.         pop pop
  256.       }
  257.       { pop exit }
  258.     ifelse
  259.   } loop
  260.   File closefile
  261. } def
  262.  
  263.  
  264. /PrintMail %% filename
  265. {
  266.   /File exch def
  267.   mark
  268.   {
  269.     File 4096 string readline
  270.     true eq
  271.       { DoListingLine }
  272.       { pop exit }
  273.     ifelse
  274.   } loop
  275.   File closefile
  276.   cleartomark
  277. } def
  278.  
  279.  
  280. /DoListingLine
  281. {
  282.   ListingFont FindFontISO ListingSize scalefont setfont
  283.   /str exch def
  284.   str stringwidth pop ColumnWidth gt
  285.   {
  286.     /ostr () def
  287.     {
  288.       str ( ) search  % remainder ( ) word true
  289.       {
  290.         /word exch ( ) concatstrings def pop
  291.         /remainder exch def
  292.         ostr word concatstrings
  293.         dup stringwidth pop ColumnWidth gt
  294.         {
  295.           pop ostr
  296.           ListingSize /Leading where {pop Leading add} if NewLine
  297.           ListingFont FindFontISO ListingSize scalefont setfont
  298.           XPos YPos moveto show
  299.           /ostr word def
  300.           /str remainder def
  301.         }
  302.         {
  303.           /ostr exch def
  304.           /str remainder def
  305.         } ifelse
  306.       }
  307.       {               % string false
  308.         /word exch ( ) concatstrings def
  309.         ostr word concatstrings
  310.         dup stringwidth pop ColumnWidth gt
  311.         {
  312.           pop ostr
  313.           ListingSize /Leading where {pop Leading add} if NewLine
  314.           ListingFont FindFontISO ListingSize scalefont setfont
  315.           XPos YPos moveto show
  316.           /ostr word def
  317.           /str () def
  318.         }
  319.         {
  320.           ListingSize /Leading where {pop Leading add} if NewLine
  321.           ListingFont FindFontISO ListingSize scalefont setfont
  322.           XPos YPos moveto show
  323.           exit
  324.         } ifelse
  325.       } ifelse
  326.     } loop
  327.   }
  328.   {
  329.     ListingSize /Leading where {pop Leading add} if NewLine
  330.     ListingFont FindFontISO ListingSize scalefont setfont
  331.     XPos YPos moveto str show
  332.   }
  333.   ifelse
  334. } def
  335.  
  336.  
  337. /NewLine %% Points
  338. {
  339.   dup
  340.   /XPos BlockLeftEdge def
  341.   /YPos exch neg YPos add def
  342.   YPos BottomMargin lt
  343.     { /YPos TopMargin def
  344.       /BlockLeftEdge BlockRightEdge Gutter add def
  345.       /BlockRightEdge BlockLeftEdge ColumnWidth add def
  346.       /XPos BlockLeftEdge def
  347.       XPos RightMargin 10 sub gt
  348.         {
  349.           EndPage BeginPage
  350.           dup /YPos exch neg YPos add def
  351.         } if
  352.     } if
  353.   pop
  354. } def
  355.  
  356.  
  357. /HeadingLeft %% Text
  358. {
  359.   HeadingSize /Leading where {pop Leading add} if NewLine
  360.   HeadingFont FindFontISO HeadingSize scalefont setfont
  361.   BlockLeftEdge YPos LeftAlign
  362. } bind def
  363.  
  364.  
  365. /HorizontalRule
  366. {
  367.   0.1 setlinewidth
  368.   ListingSize NewLine
  369.   LeftMargin -10 add YPos moveto
  370.   RightMargin 10 add YPos lineto stroke
  371.   ListingSize NewLine
  372. } def
  373.  
  374.  
  375. /PlaceMail %% filename - use this if you want to print mails from
  376.            %% GhostScript's command line.
  377. {
  378.   /FileName exch def
  379.   FileName (r) file PrintMail
  380. } def
  381.  
  382.  
  383. /BeginMail
  384. {
  385.   /PageNo 1 def BeginPage
  386.   PrintMailHeaders
  387.   BodySize /Leading where {pop Leading add } if NewLine
  388.   /ListingSize BodySize def
  389.   /ListingFont BodyFont def
  390. } def
  391.  
  392.  
  393. /EndMail
  394. {
  395.   EndPage
  396. } def
  397.  
  398.  
  399. %% EndProlog
  400.  
  401.